package 蓝桥算法;

import 二叉树.TreeNode;

public class day19 {
    int getHeight(TreeNode node){//最大深度
        if(node==null){
            return 0;
        }
        int leftHeight=getHeight(node.left);
        int rightHeight=getHeight(node.right);
        return 1+Math.max(leftHeight,rightHeight);
    }
    boolean compare(TreeNode left,TreeNode right){//判断对称二叉树
        if(left==null&&right!=null){
            return false;
        }
        else if(left!=null&&right==null){
            return false;
        }
        else if(left==null&&right==null){
            return true;
        }
        else if(left.val!=right.val){
            return false;
        }
        boolean leftvalue=compare(left.left,right.right);
        boolean rightvalue=compare(left.right,right.left);
        if(leftvalue&&rightvalue){
            return true;
        }
        return true;
    }
    int minDepth(TreeNode node){//最小深度，存在坑
        if(node==null){
            return 0;
        }
        int leftDpeth=minDepth(node.left);
        int rightDepth=minDepth(node.right);
        if(node.left!=null&&node.right==null){
            return leftDpeth+1;
        }
        else if(node.left==null&&node.right!=null){
            return  rightDepth+1;
        }
        else {
            return Math.min(leftDpeth,rightDepth)+1;
        }
    }
    int getNums(TreeNode node){//普通递归
        if(node==null){
            return 0;
        }
        int leftnums=getNums(node.left);
        int rightnums=getNums(node.right);
        return leftnums+rightnums;
    }
    int getNums1(TreeNode node){
        if(node==null){
            return 0;
        }
        TreeNode left=node.left;
        TreeNode right=node.right;
        int leftHeight= 0;
        int rightHeight=0;
        while(left!=null){
            left=left.left;
            leftHeight++;
        }
        while(right!=null){
            right=right.right;
            rightHeight++;
        }
        if(rightHeight==leftHeight){
            return (2<<leftHeight)-1;
        }
        else {//不符合条件向下递归
            int leftNums=getNums1(left);
            int rightNums=getNums1(right);
            int nums=leftNums+rightNums;
            return nums;
        }
    }
}
